package com.wl.shop.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.wl.shop.dao.RoleDao;
import com.wl.shop.entity.Role;

@Service("roleService")
@Transactional(readOnly = true)
public class RoleService {
	@Autowired
	private RoleDao roleDao;
	
	public Page<Role> listByParam(Page<Role> page,EntityWrapper<Role> wrapper){
		List<Role> menuList =roleDao.selectRolePage(page);
		page.setRecords(menuList);
		return	page; 
	}
	
	public List<Role> listByParam(EntityWrapper<Role> wrapper){
		List<Role> menuList = roleDao.selectList(wrapper);
		return menuList;
	}
	
	public int getCount(EntityWrapper<Role> wrapper){
		return roleDao.selectCount(wrapper);
	}
	
	public void saveOrUpdate(Role role){
		if(role.getId() == null || "".equals(role.getId())){
			role.preInsert();
			roleDao.insert(role);
		}else{
			role.preUpdate();
			roleDao.updateById(role);
		}
	}
	
	public Role selectById(String id){
		return roleDao.selectById(id);
	}
}
